using System;


namespace Framework.Event
{
    public partial class EventDispatcher
    {
        private interface IDispatcherEvent
        {
            void Handle();
            void Handle(object a);
            void Handle(object a, object b);
            void Handle(object a, object b, object c);
            void AddAction(object a);
            void DelAction(object a);
            bool IsEmpty();
        }

        private class DispatcherEvent : BaseEvent, IDispatcherEvent, IReference
        {
            private event FrameworkAction m_Action;
            private int m_Count = 0;

            public override void Run()
            {
                this.m_Action();
            }

            public void AddAction(object a)
            {
                this.m_Action += (FrameworkAction)a;
                this.m_Count++;
            }

            public void DelAction(object a)
            {
                this.m_Action -= (FrameworkAction)a;
                this.m_Count--;
            }

            public bool IsEmpty()
            {
                return this.m_Count <= 0;
            }

            public void OnFetch()
            {
                this.m_Count = 0;
            }

            public void OnRecycle()
            {
                if (this.m_Action == null)
                {
                    return;
                }
                foreach (Delegate del in this.m_Action.GetInvocationList())
                {
                    this.m_Action -= del as FrameworkAction;
                }
            }
        }

        private class DispatcherEvent<A> : BaseEvent<A>, IDispatcherEvent, IReference
        {
            public event FrameworkAction<A> m_Action;
            private int m_Count = 0;

            public override void Run(A a)
            {
                this.m_Action(a);
            }

            public void AddAction(object a)
            {
                this.m_Action += (FrameworkAction<A>)a;
                this.m_Count++;
            }

            public void DelAction(object a)
            {
                this.m_Action -= (FrameworkAction<A>)a;
                this.m_Count--;
            }

            public bool IsEmpty()
            {
                return this.m_Count <= 0;
            }

            public void OnFetch()
            {
                this.m_Count = 0;
            }

            public void OnRecycle()
            {
                if (this.m_Action == null)
                {
                    return;
                }
                foreach (Delegate del in this.m_Action.GetInvocationList())
                {
                    this.m_Action -= del as FrameworkAction<A>;
                }
            }
        }

        private class DispatcherEvent<A, B> : BaseEvent<A, B>, IDispatcherEvent, IReference
        {
            public event FrameworkAction<A, B> m_Action;
            private int m_Count = 0;

            public override void Run(A a, B b)
            {
                this.m_Action(a, b);
            }

            public void AddAction(object a)
            {
                this.m_Action += (FrameworkAction<A, B>)a;
                this.m_Count++;
            }

            public void DelAction(object a)
            {
                this.m_Action -= (FrameworkAction<A, B>)a;
                this.m_Count--;
            }

            public bool IsEmpty()
            {
                return this.m_Count <= 0;
            }

            public void OnFetch()
            {
                this.m_Count = 0;
            }

            public void OnRecycle()
            {
                if (this.m_Action == null)
                {
                    return;
                }
                foreach (Delegate del in this.m_Action.GetInvocationList())
                {
                    this.m_Action -= del as FrameworkAction<A, B>;
                }
            }
        }

        private class DispatcherEvent<A, B, C> : BaseEvent<A, B, C>, IDispatcherEvent, IReference
        {
            public event FrameworkAction<A, B, C> m_Action;
            private int m_Count = 0;

            public override void Run(A a, B b, C c)
            {
                this.m_Action(a, b, c);
            }

            public void AddAction(object a)
            {
                this.m_Action += (FrameworkAction<A, B, C>)a;
                this.m_Count++;
            }

            public void DelAction(object a)
            {
                this.m_Action -= (FrameworkAction<A, B, C>)a;
                this.m_Count--;
            }

            public bool IsEmpty()
            {
                return this.m_Count <= 0;
            }

            public void OnFetch()
            {
                this.m_Count = 0;
            }

            public void OnRecycle()
            {
                if (this.m_Action == null)
                {
                    return;
                }
                foreach (Delegate del in this.m_Action.GetInvocationList())
                {
                    this.m_Action -= del as FrameworkAction<A, B, C>;
                }
            }
        }
    }
}